﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Admin.Controllers;
using PHMEE.Constants;
using PHMEE.ToolKits;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace PHMEE.Admin.HttpApi.Controllers.BaseInfo.Bears
{
    /// <summary>
    /// 轴承库管理🚢🌞🌛✨
    /// </summary>
    [Route("phmeeadmin/api/bear")]
    public class BearController : PHMEEAdminController
    {
        private readonly IBearAppService bearAppService;

        /// <summary>
        /// 构造器注入
        /// </summary>
        /// <param name="bearAppService"></param>
        public BearController(IBearAppService bearAppService)
        {
            this.bearAppService = bearAppService;
        }

        /// <summary>
        /// 创建轴承库厂商
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateBearFactory")]
        public async Task<int> CreateBearFactory(BearFactoryCreateDto input)
        {
            return await bearAppService.CreateBearFactoryAsync(input);
        }

        /// <summary>
        /// 更新轴承库厂商
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("UpdateBearFactory")]
        public async Task UpdateBearFactory(BearFactoryUpdateDto input)
        {
            await bearAppService.UpdateBearFactoryAsync(input);
        }

        /// <summary>
        /// 轴承库厂商详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetBearFactoryById")]
        public async Task<BearFactoryDto> GetBearFactoryById(int id)
        {
            return await bearAppService.GetBearFactoryByIdAsync(id);

        }

        /// <summary>
        /// 删除轴承库厂商
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("DeleteBearFactory")]
        public async Task DeleteBearFactory(int id)
        {
            await bearAppService.DeleteBearFactoryAsync(id);

        }

        /// <summary>
        /// 轴承库厂商分页集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetPagedBearFactories")]
        public async Task<PagedResultDto<BearFactoryDto>> GetPagedBearFactories(BearFactoryListDto input)
        {
            return await bearAppService.GetPagedBearFactoriesAsync(input);
        }




        /// <summary>
        /// 创建轴承库
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateBearLib")]
        public async Task<Guid> CreateBearLib(BearLibCreateDto input)
        {
            return await bearAppService.CreateBearLibAsync(input);
        }

        /// <summary>
        /// 更新轴承库
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("UpdateBearLib")]
        public async Task UpdateBearLib(BearLibUpdateDto input)
        {
            await bearAppService.UpdateBearLibAsync(input);
        }

        /// <summary>
        /// 轴承库详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetBearLibById")]
        public async Task<BearLibDto> GetBearLibById(Guid id)
        {
            return await bearAppService.GetBearLibByIdAsync(id);

        }

        /// <summary>
        /// 轴承库详情
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetBearLibByModel")]
        public async Task<BearLibDto> GetBearLibByModel(string model)
        {
            return await bearAppService.GetBearLibByModelAsync(model);

        }


        /// <summary>
        /// 删除轴承库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("DeleteBearLib")]
        public async Task DeleteBearLib(Guid id)
        {
            await bearAppService.DeleteBearLibAsync(id);

        }

        /// <summary>
        /// 轴承库分页集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetPagedBearLibs")]
        public async Task<PagedResultDto<BearLibDto>> GetPagedBearLibs(BearLibListDto input)
        {
            return await bearAppService.GetPagedBearLibsAsync(input);
        }

        /// <summary>
        /// 下载轴承库Excel模板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GenerateBearLibTemplate")]
        public async Task<FileContentResult> GenerateBearLibTemplate()
        {
            byte[] bytes = await bearAppService.GenerateBearLibTemplateAsync();
            return File(bytes, PhmeeConst.Mimexlsx,"轴承库模板.xlsx");
        }

        /// <summary>
        /// 批量导入轴承库Excel
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("ImportBearLibs")]
        public async Task<OperationResult> ImportBearLibs(IFormFile file)
        {

            return await bearAppService.ImportBearLibsAsync(await file.GetAllBytesAsync(), file.FileName);

        }

    }
}
